

export default class RunContext{

    static getInstance( ) {
        if(!this.instance) {
            this.instance =new RunContext();
        }
        return this.instance;
    }

    constructor(){
        this.runEntitys=[];
        this.suspend=0
    }


    run(){
        let _this=this;
        while (   _this.runEntitys.length >0 && _this.suspend ==0){
            let runEntity= _this.runEntitys[_this.runEntitys.length-1];

            runEntity.run()
            if(runEntity.coordinate >= runEntity.commands.length){
                _this.runEntitys.splice(_this.runEntitys.length-1,1);
            }
        }
    }

    add(runEntitys){
        this.runEntitys.push(runEntitys)
        this.run()
    }
}